﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DailyComics.Common.Utilities;

namespace DailyComics.Common.Model.CachingStrategies
{
  public class MemoryCacheStrategy : ICachingStrategy
  {
    private static Dictionary<DateTime, byte[]> cache;
    private int capacity;

    public MemoryCacheStrategy(int capacity)
    {
      cache = new Dictionary<DateTime, byte[]>();
      this.capacity = capacity;
    }

    #region ICachingStrategy Members

    public void Add(DateTime date, byte[] image)
    {
      if (Contains(date)) return;

      cache.Add(date, image);
    }

    public byte[] Get(DateTime date)
    {
      return cache[date];
    }

    public bool Contains(DateTime date)
    {
      return cache.ContainsKey(date);
    }

    public void Clear()
    {
      cache.Clear();
    }

    #endregion
  }
}
